package com.gpframework.module.purchase.domain.req;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.gpframework.common.utils.DateUtils;
import com.gpframework.common.utils.StringUtils;
import com.gpframework.module.base.domain.req.BaseReq;
import com.gpframework.module.purchase.domain.GpProcureScheduling;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @ClassName GpProcureSchedulingReq
 * @Author gpframework
 * @Date 2023-12-22
 * @Version 1.0.0
 * @Description 列表查询信息体
 */
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
public class GpProcureSchedulingReq extends BaseReq {
    private static final long serialVersionUID = 1L;

         @ApiModelProperty("品牌id")
     private String brandId;
     @ApiModelProperty("品牌名称")
     private String brandName;
     @ApiModelProperty("缺货报库存申请表id")
     private Long productionApplicationId;
     @ApiModelProperty("做货明细表id")
     private Long purchasingDetailsId;
     @ApiModelProperty("排单号")
     private String sn;
     @ApiModelProperty("供应商")
     private String supplier;
     @ApiModelProperty("品名")
     private String productName;
     @ApiModelProperty("颜色")
     private String productColor;
     @ApiModelProperty("手感")
     private String feel;
     @ApiModelProperty("克重")
     private Long fabricWeight;
     @ApiModelProperty("下机幅宽")
     private String lowerMachineWidth;
     @ApiModelProperty("规格")
     private String norms;
     @ApiModelProperty("其他")
     private String other;
     @ApiModelProperty("密度")
     private String density;
     @ApiModelProperty("图片")
     private String picture;
     @ApiModelProperty("备注")
     private String remarks;
     @ApiModelProperty("申请人id")
     private Long enteredId;
     @ApiModelProperty("申请人")
     private String enteredMan;
     @ApiModelProperty("申请时间")
     private Date enteredTime;
     @ApiModelProperty("操作人id")
     private Long merchandiserId;
     @ApiModelProperty("操作人")
     private String merchandiser;
     @ApiModelProperty("操作时间")
     private Date operatorTime;
     @ApiModelProperty("关联需求单号")
     private String relatedNeedNumber;
    @ApiModelProperty("查询条件（订单号/客户名）")
    private String searchName;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date searchDate;

    /**
    * @Description 生成查询wrapper
    * @Author greatplan@qq.com
    * @Date 2020-11-04 16:04
    * @Param [lqw]
    * @Param [isVO] 是否vo查询体，true的话走的是mapper.xml里面的查询语句，不过查询语法还是mybatis-plus，主要用于某些关联查询出一些非数据表字段
    * @Return void
    */
    public void generatorQuery(QueryWrapper<GpProcureScheduling> lqw,boolean isVo) {
        String alias = "";
        if (isVo) {
            alias = "gp.";
            lqw.eq(alias+"del_status",0);
            lqw.orderByDesc(alias + "create_time");
        }
        if (StringUtils.isNotBlank(this.getBrandId())){
        lqw.eq(alias+"brand_id" ,this.getBrandId());
        }
        if (StringUtils.isNotBlank(this.getBrandName())){
            lqw.like(alias+"brand_name",this.getBrandName());
        }
        if (this.getProductionApplicationId() != null){
        lqw.eq(alias+"production_application_id" ,this.getProductionApplicationId());
        }
        if (this.getPurchasingDetailsId() != null){
        lqw.eq(alias+"purchasing_details_id" ,this.getPurchasingDetailsId());
        }
        if (StringUtils.isNotBlank(this.getSn())){
        lqw.eq(alias+"sn" ,this.getSn());
        }
        if (StringUtils.isNotBlank(this.getSupplier())){
        lqw.eq(alias+"supplier" ,this.getSupplier());
        }
        if (StringUtils.isNotBlank(this.getProductName())){
            lqw.like(alias+"product_name",this.getProductName());
        }
        if (StringUtils.isNotBlank(this.getProductColor())){
        lqw.like(alias+"product_color" ,this.getProductColor());
        }
        if (StringUtils.isNotBlank(this.getFeel())){
        lqw.eq(alias+"feel" ,this.getFeel());
        }
        if (this.getFabricWeight() != null){
        lqw.eq(alias+"fabric_weight" ,this.getFabricWeight());
        }
        if (this.getLowerMachineWidth() != null){
        lqw.eq(alias+"lower_machine_width" ,this.getLowerMachineWidth());
        }
        if (StringUtils.isNotBlank(this.getNorms())){
        lqw.eq(alias+"norms" ,this.getNorms());
        }
        if (StringUtils.isNotBlank(this.getOther())){
        lqw.eq(alias+"other" ,this.getOther());
        }
        if (StringUtils.isNotBlank(this.getDensity())){
        lqw.eq(alias+"density" ,this.getDensity());
        }
        if (StringUtils.isNotBlank(this.getPicture())){
        lqw.eq(alias+"picture" ,this.getPicture());
        }
        if (StringUtils.isNotBlank(this.getRemarks())){
        lqw.eq(alias+"remarks" ,this.getRemarks());
        }
        if (this.getEnteredId() != null){
        lqw.eq(alias+"entered_id" ,this.getEnteredId());
        }
        if (StringUtils.isNotBlank(this.getEnteredMan())){
        lqw.eq(alias+"entered_man" ,this.getEnteredMan());
        }
        if (this.getEnteredTime() != null){
        lqw.eq(alias+"entered_time" ,this.getEnteredTime());
        }
        if (this.getMerchandiserId() != null){
        lqw.eq(alias+"merchandiser_id" ,this.getMerchandiserId());
        }
        if (StringUtils.isNotBlank(this.getMerchandiser())){
        lqw.eq(alias+"merchandiser" ,this.getMerchandiser());
        }
        if (this.getOperatorTime() != null){
        lqw.eq(alias+"operator_time" ,this.getOperatorTime());
        }
        if (StringUtils.isNotBlank(this.getRelatedNeedNumber())){
        lqw.eq(alias+"related_need_number" ,this.getRelatedNeedNumber());
        }
        if (StringUtils.isNotBlank(this.getSearchName())) {
            lqw.and(wrapper -> wrapper.like("gp.sn", this.getSearchName()).or().like("gp.product_name", this.getSearchName()).or().like("gp.product_color", this.getSearchName()));
        }
        if (this.getSearchDate() != null) {
            lqw.apply("DATE_FORMAT(gp.create_time, '%Y-%m-%d') = '" + DateUtils.dateTime(this.getSearchDate()) + "'");
        }
    }
}
